#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 2e5 + 10;
int a[N];
int n, m;
int find(int x)
{
    return a[x] == x ? x : a[x] = find(a[x]);
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        a[i] = i;
    }
    while (m--)
    {
        int z, x, y;
        cin >> z >> x >> y;
        if (z == 1)
        {
            int s = find(x);
            int v = find(y);
            a[v] = s;
        }
        else
        {
            if (find(x) == find(y))
            {
                cout << 'Y' << endl;
            }
            else
            {
                cout << 'N' << endl;
            }
        }
    }
    return 0;
}